package bizapi.sinosoft.com.provider.product;
import bizapi.sinosoft.com.provider.CommonResponse;
import com.weibo.api.motan.config.springsupport.annotation.MotanReferer;
import jd.api.service.product.JdProductApi;
import jd.api.vo.product.ProductCheckRepVO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import utils.Lang;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/2/8.
 */
@RestController
@RequestMapping("api/product")
public class ProductRestController {
    @MotanReferer
    JdProductApi jdProductApi;
    @RequestMapping(value = "check",method = RequestMethod.POST)
    public CommonResponse<List<ProductCheckRepVO>> check(String skuIds) {
        CommonResponse<List<ProductCheckRepVO>> commonResponse = new CommonResponse();
        try{
            String[] skuids = skuIds.split(",");
            List<Long> skuIdsList = new ArrayList<>();
            for(int i = 0;i<skuids.length;i++){
                Long skuId = Long.parseLong(skuids[i]);
                skuIdsList.add(skuId);
            }
            List<ProductCheckRepVO> productCheckRepVOS = jdProductApi.getSkuCheck(skuIdsList).getResult();
            if(Lang.isEmpty(productCheckRepVOS)){
               commonResponse.setSuccess(false);
            }else {
                commonResponse.setResult(productCheckRepVOS);
                commonResponse.setSuccess(true);
            }
            return commonResponse;
        }catch (Exception e){
            commonResponse.setResultMessage(e.getMessage());
            commonResponse.setSuccess(false);
            return commonResponse;
        }
    }
}
